<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

    <script>
        
        {

            // 单例模式

            let coder1 = {
                name: 'ws',
                age: 10,
                job: 'coder',
                fn: function () {
                    console.log('coder1');
                }
            };

            let coder2 = {
                name: 'ww',
                age: 20,
                job: 'coder',
                fn: function () {  
                    console.log('coder2');
                }

            };

            console.log(coder1.fn());
            console.log(coder2.fn());
            
        }

        {
            // 工厂模式

            function createCoder (name,age,job) {
                var obj = {};
                obj.name = name;
                obj.age = age;
                obj.job = job;
                return obj;
            }

            console.log(createCoder('ww',20,'coder1'));
            console.log(createCoder('ss',15,'coder2'));
            console.log(createCoder('xx',18,'coder3'));


        }

        {
            // 构造函数

            function Coder (name,age,job) {
                this.name = name;
                this.age =age;
                this.job = job;
                return this;
            }

            let coder1 = new Coder('Will',28,'coder');
            console.log(coder1);

        }

        

    </script>

</body>
</html>